package logic

import (
	"context"
	"github.com/pkg/errors"
	"user-srv/model/mysql"

	"user-srv/internal/svc"
	"user-srv/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type SaveRealAuthInfoLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewSaveRealAuthInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SaveRealAuthInfoLogic {
	return &SaveRealAuthInfoLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *SaveRealAuthInfoLogic) SaveRealAuthInfo(in *user.SaveRealAuthInfoRequest) (*user.SaveRealAuthInfoResponse, error) {
	// todo: add your logic here and delete this line
	r := mysql.RealAuth{
		UserId:   in.UserId,
		RealName: in.RealName,
		IdCard:   in.IdCard,
	}
	err := r.CreateRealAuth()
	if err != nil {
		return nil, errors.New("添加实名信息失败")
	}
	return &user.SaveRealAuthInfoResponse{}, nil
}
